package com.major.crowd.mvc.controller;

import com.major.crowd.entity.Admin;
import com.major.crowd.service.api.AdminService;
import com.major.crowd.util.CrowdUtil;
import com.major.crowd.util.ResultEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class TestController {
    @Autowired
    private AdminService adminService;

    Logger logger = LoggerFactory.getLogger(this.getClass());


    @RequestMapping("send/array.html")
    @ResponseBody
    public String testReceiveArrayOne(@RequestParam("array[]") List<Integer> array){
        for (Integer num :array) {
            System.out.println(num);
        }
        return "success";
    }

    @RequestMapping("send/array2.html")
    @ResponseBody
    public String testReceiveArrayTwo(@RequestBody Integer[] array,HttpServletRequest request){

        boolean judgeResult = CrowdUtil.judgeRequestType(request);
        logger.info("judgeResult="+judgeResult);

        System.out.println(10/0);

        for (Integer num :array) {
            logger.info("num:"+ num);
            System.out.println(num);
        }
        return "target";
    }

    @RequestMapping("/test/ssm.html")
    public String testSsm(ModelMap modelMap, HttpServletRequest request) {
        boolean judgeResult = CrowdUtil.judgeRequestType(request);
        logger.info("judgeResult="+judgeResult);

//        List<Admin> adminList = adminService.getAll();
//        modelMap.addAttribute("adminList", adminList);

        String a = null;
        System.out.println(a.length());

        //System.out.println(10/0);
        return "target";
    }

    /*@RequestMapping("send/array3111.json")
    @ResponseBody
    public ResultEntity<Student> testReceiveArrayThree(@RequestBody Student student ,HttpServletRequest request){
        logger.info(student.toString());
        boolean judgeResult = CrowdUtil.judgeRequestType(request);
        logger.info("judgeResult:"+judgeResult);
        ResultEntity<Student> resultEntity = ResultEntity.successWithData(student);

        String s = null;
        System.out.println(s.length());

        return resultEntity;
    }

    @ResponseBody
    @RequestMapping("/send/array3.json")
    public ResultEntity<Student> testReceiveComposeObject(@RequestBody Student student, HttpServletRequest request) {

        boolean judgeResult = CrowdUtil.judgeRequestType(request);
        logger.info("judgeResult="+judgeResult);
        logger.info(student.toString());
        // 将“查询”到的Student对象封装到ResultEntity中返回
        ResultEntity<Student> resultEntity = ResultEntity.successWithData(student);
        //String a = null;
        //System.out.println(a.length());
        return resultEntity;
    }*/
}
